//
//  TopView.m
//  BTRIP
//
//  Created by dllo on 15/11/15.
//  Copyright © 2015年 johnbk. All rights reserved.
//

#import "TopView.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>
@implementation TopView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)dealloc{
    [_frontImage release];
    [_allLabel release];
    [_userImage release];
    [_nameLabel release];
    [_userLabel release];
    [_label release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.frontImage = [[UIImageView alloc]init];
//        self.frontImage.backgroundColor = [UIColor blackColor];
        [self addSubview:self.frontImage];
        [_frontImage release];
        
        self.label = [[UILabel alloc]init];
//        self.label.backgroundColor = [UIColor blackColor];
        self.label.alpha = 0.01;
        [self addSubview:self.label];
        [_label release];
        
        self.userLabel = [[UILabel alloc]init];
        self.userLabel.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.userLabel];
        [_userLabel release];
        
        self.userImage = [[UIImageView alloc]init];
//        self.userImage.backgroundColor = [UIColor redColor];
        [self addSubview:self.userImage];
        [_userImage release];
        
        self.nameLabel = [[UILabel alloc]init];
//        self.nameLabel.backgroundColor = [UIColor orangeColor];
        [self addSubview:self.nameLabel];
        [_nameLabel release];
        
        self.allLabel = [[UILabel alloc]init];
//        self.allLabel.backgroundColor = [UIColor brownColor];
        [self addSubview:self.allLabel];
        [_allLabel release];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.frontImage.frame = CGRectMake(0, 0, KWIDTH, KHEIGHT / 3);
    self.label.frame = CGRectMake(0, 0, KWIDTH, KHEIGHT / 3);
    self.userLabel.frame = CGRectMake(20 * SWIDTH, self.frontImage.frame.size.height / 1.5, 56 * SWIDTH, 56 * SWIDTH);
    self.userLabel.layer.cornerRadius = self.userLabel.frame.size.width / 2;
    self.userLabel.layer.masksToBounds = YES;
    self.userImage.frame = CGRectMake(0, 0, 52 * SWIDTH, 52 * SWIDTH);
    self.userImage.center = self.userLabel.center;
    self.userImage.layer.cornerRadius = self.userImage.frame.size.width / 2;
    self.userImage.layer.masksToBounds = YES;
    
    self.nameLabel.frame = CGRectMake(self.userLabel.frame.origin.x + self.userLabel.frame.size.width + 12 , self.userLabel.frame.origin.y, 250 * SWIDTH, 36 * SWIDTH);
    self.nameLabel.textColor = [UIColor whiteColor];
    self.nameLabel.font = [UIFont systemFontOfSize:20];
    self.allLabel.textColor = [UIColor whiteColor];
    self.allLabel.font = [UIFont systemFontOfSize:14];
    self.allLabel.frame = CGRectMake(self.nameLabel.frame.origin.x, self.nameLabel.frame.origin.y + self.nameLabel.frame.size.height, self.nameLabel.frame.size.width, 30);
    
}
- (void)setFirstDetail:(FirstDetailTravelModel *)firstDetail{
    if (_firstDetail != firstDetail) {
        [_firstDetail release];
        _firstDetail = [firstDetail retain];
    }
    
    NSURL *url1 = [NSURL URLWithString:[NSString stringWithFormat:@"%@",firstDetail.front_cover_photo_url]];
//    NSLog(@"%@",url1);
    
    [self.frontImage sd_setImageWithURL:url1 placeholderImage:[UIImage imageNamed:@"background"]];
    
    
    NSURL *url2 = [NSURL URLWithString:[NSString stringWithFormat:@"%@",[firstDetail.user objectForKey:@"image"]]];
    [self.userImage sd_setImageWithURL:url2 placeholderImage:[UIImage imageNamed:@"background"]];
    self.nameLabel.text = firstDetail.name;
    self.allLabel.text = [NSString stringWithFormat:@"%@/ %ld天/ %@图",firstDetail.start_date,firstDetail.trip_days.count,firstDetail.photos_count];
    
}





@end
